{% extends 'admin/indexBase.html' %}

{% block title %}用户管理{% endblock %}

{% block search %}
    <form class="navbar-form navbar-right" method="get" action="{{ url_for('userAdmin.search') }}">
        <input type="text" class="form-control" name="kw" placeholder="Search...Users">
        <input type="submit" class="form-control" value="搜索">
    </form>
{% endblock %}

{% block main %}
    <h2 class="sub-header">用户列表</h2>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>#</th>
                <th>用户名</th>
                <th>手机号</th>
                <th>email</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for user in users %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td>{% if user.name == None %}{% else %}{{ user.name }}{% endif %}</td>
                    <td>{{ user.tel }}</td>
                    <td>{% if user.email == None %}{% else %}{{ user.email }}{% endif %}</td>
                    <td>
                        <a type="button" class="btn btn-primary" role="button"
                           onclick="resetPwd('{{ user.id }}')">重置密码</a>&nbsp;&nbsp;
                        {% if user.is_freezing %}
                            <a type="button" class="btn btn-danger" role="button"
                               onclick="activate_user('{{ user.id }}')">激活账户</a>
                        {% else %}
                            <a type="button" class="btn btn-danger" role="button"
                               onclick="freezing_user('{{ user.id }}')">冻结账户</a>
                        {% endif %}
                        &nbsp;
                        <button type="button" class="btn btn-danger" onclick="add_user_to_trash('{{ user.id }}')">
                            删除
                        </button>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    <div id="pages">

    </div>
    <script>
        new Pagination({
            element: '#pages',
            type: 1,
            pageIndex: {{ active_page }},   //默认活动页
            pageSize: {{ page_size }},	//一页数量
            pageCount: {{ page_count }},   //显示页数
            total: {{ total }},      //总数
            jumper: true,
            singlePageHide: false,
            prevText: '上一页',
            nextText: '下一页',
            disabled: false,
            currentChange: function (index) {
                console.log(index);
                //https://blog.csdn.net/pengShuai007/article/details/86528992
                var a = document.createElement('a');
                a.setAttribute('href', '/admin/userAdmin?page='+index);
                // 防止反复添加
                if (document.getElementById('startTelMedicine')) {
                    document.body.removeChild(document.getElementById('startTelMedicine'));
                }
                document.body.appendChild(a);
                a.click();
            }
        });
    </script>
{% endblock %}

{% block js_bottom %}
    <script src="{{ url_for('static', filename='js/admin/admin_bottom.js') }}"></script>
{% endblock %}